{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8ddc2bc7-042f-4552-92a3-f9047a132e56",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30c3a8f2-797e-4427-9acd-0ea951421e92",
   "metadata": {},
   "source": [
    "### Determinant of a square array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "16a039d2-473c-4b23-8d08-108b0edae19b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter size of square array:  2\n",
      "Enter a square array in row-wise manner:  3 4 2 2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "SUCCESS: Reshape operation completed\n",
      "Given square array is\n",
      "[[3 4]\n",
      " [2 2]]\n",
      "\n",
      "The approx. determinant of the above square array is -2.0\n",
      "The absolute determinant of the above square array is -1.9999999999999998\n"
     ]
    }
   ],
   "source": [
    "arr_shape = int(input(\"Enter size of square array: \"))\n",
    "arr = list(map(int,input(\"Enter a square array in row-wise manner: \").split()))\n",
    "\n",
    "if len(arr) == arr_shape**2 :\n",
    "    sq_arr = np.array(arr, dtype=int).reshape(arr_shape, arr_shape)\n",
    "    print(\"\\nSUCCESS: Reshape operation completed\")\n",
    "    print(f\"Given square array is\")\n",
    "    print(sq_arr)\n",
    "    print(f\"\\nThe approx. determinant of the above square array is {round(np.linalg.det(sq_arr),0)}\")\n",
    "    print(f\"The absolute determinant of the above square array is {np.linalg.det(sq_arr)}\")\n",
    "else:\n",
    "    print(f\"ERROR: Cannot reshape array of size {len(arr)} into {(arr_shape, arr_shape)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35643ed3-5bfe-443a-adf0-df266ba9da72",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
